
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

################################################################################

import csv
from datetime import datetime
import numpy as np

from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

################################################################################
#
# 数据可视化，显示北京2020-1-1至2020-12-31时间内的天气情况
# 数据来源，https://rp5.ru/
# 原始数据保:datasouce/54511.01.01.2020.31.12.2020.1.0.0.cn.utf8.00000000.csv
#
################################################################################

def weather_year():
    """ 北京2020全年最高最低气温
    """
    filename = "54511-1.csv"

    dates, height, low = [], [], []
    with open(filename, encoding="utf-8") as f:
        reader = csv.reader(f, delimiter=";")
        next(reader)

        for row in reader:
            if "11:00" not in row[0]:
                continue

            strpt = datetime.strptime(row[0], r'%d.%m.%Y %H:%M')
            dates.append(strpt)

            row_14 = row[14]
            if row_14:
                row_14 = float(row_14)
            else:
                row_14 = 0
            low.append(row_14)

            row_15 = row[15]
            if row_15:
                row_15 = float(row_15)
            else:
                row_15 = 0
            height.append(row_15)

    # 构建可视化窗口
    # dpi,分辨率
    # figsize, 窗口大小
    fig:Figure = plt.figure(dpi=128, figsize=(10, 6))
    # 创建3d
    ax = Axes3D(fig)


    # x = height
    # y = low
    # x, y = np.meshgrid(x, y)
    # z = dates
    # y3 = np.arctan2(x,y)
    # ax.scatter(x, y, z, c=y3, marker='.', s=50, label='')


    x = np.arange(0, 200)
    y = np.arange(0, 100)
    x, y = np.meshgrid(x, y)
    z = np.random.randint(0, 200, size=(100, 200))
    y3 = np.arctan2(x,y)
    ax.scatter(x, y, z, c=y3, marker='.', s=50, label='')


    # # 设置数据及线条颜色
    # plt.plot(dates, height, c='red')
    # plt.plot(dates, low, c='blue')
    # plt.fill_between(dates, height, low, facecolor="blue", alpha=0.1)

    # plt.bar(dates, height, fc='red')
    # plt.bar(dates, low, fc='blue')

    # for i in range(len(dates)):
    #     x_d = dates[i]
    #     y_d = height[i]
    #     plt.scatter(x_d, y_d, c="red")

    #     y_d_l = low[i]
    #     plt.scatter(x_d, y_d_l, c="blue")

    # # 设置标题
    # plt.title("Daily high temperatures - 2014", fontsize=24)
    # # 设置x轴标签
    # plt.xlabel('', fontsize=14)
    # # 设置斜的日期格式
    # fig.autofmt_xdate()
    # # 设置y轴标签
    # plt.ylabel("Temperature (F)", fontsize=14)

    plt.show()


if __name__ == "__main__":
    weather_year()
